﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using BCNPCObject.DB;
using DbLinq;
using DbLinq.Oracle;
using CMISLibrary.Entities;
using CMISLibrary;
namespace BCNPCObject.EXCEL
{
    public class cls_DD_BDONG_TTHAO_Controller
    {
        #region   Atributes

        //private DataSet CMIS_Header = new CMISOutputParameter();
        private DD_BDONG_TTHAO info;

        #endregion

        #region   Constructor

        public cls_DD_BDONG_TTHAO_Controller()
        {
            info = new DD_BDONG_TTHAO();
        }
        public cls_DD_BDONG_TTHAO_Controller(DD_BDONG_TTHAO Info)
        {
            this.info = Info;
        }

        #endregion

        #region   Properties

        public DD_BDONG_TTHAO pInfor
        {
            get { return info; }
            set { info = value; }
        }

        #endregion

        #region Methods
        public bool insert_DD_BDONG_TTHAO(ref long id_ls_treothao, ref string maloi)
        {
            long _ID = CMIS2.DB.ExecuteCommand("Select SEQ_DD_BDONG_TTHAO.NEXTVAL from dual");
            if (_ID == -1) return false;
            try
            {
                info.ID_LSU_TTHAO = Convert.ToInt64(_ID);
                DD_BDONG_TTHAO objDD_BDONG_TTHAO = new DD_BDONG_TTHAO()
                {
                    MA_DVIQLY = info.MA_DVIQLY,
                    ID_LSU_TTHAO = info.ID_LSU_TTHAO,
                    ID_BBAN = info.ID_BBAN,
                    MA_DDO = info.MA_DDO,
                    MA_KHANG = info.MA_KHANG,
                    TEN_KHANG = info.TEN_KHANG,
                    DCHI_KHANG = info.DCHI_KHANG,
                    DCHI_DDO = info.DCHI_DDO,
                    MA_SOGCS = info.MA_SOGCS,
                    MA_TRAM = info.MA_TRAM,
                    KVUC_STT = info.KVUC_STT,
                    LOAI_DDO = info.LOAI_DDO,
                    DDO_KHANG = info.DDO_KHANG,
                    MA_BDONG = info.MA_BDONG,
                    SO_PHA = info.SO_PHA,
                    LOAI_KHANG = info.LOAI_KHANG,
                    NGAY_BDONG = info.NGAY_BDONG,
                    NGAY_KCHI = info.NGAY_KCHI,
                    MA_NVIEN = info.MA_NVIEN,
                    MA_NVKCHI = info.MA_NVKCHI,
                    MA_LDO = info.MA_LDO,
                    MA_TBI = info.MA_TBI,
                    LOAI_TBI = info.LOAI_TBI,
                    SO_TBI = info.SO_TBI,
                    MA_CLOAI = info.MA_CLOAI,
                    VTRI_TREO = info.VTRI_TREO,
                    BCS = info.BCS,
                    LOAI_CHISO = info.LOAI_CHISO,
                    SO_COT = info.SO_COT,
                    SO_HOM = info.SO_HOM,
                    CHISO_CU = info.CHISO_CU,
                    CHISO_MOI = info.CHISO_MOI,
                    SAN_LUONG = info.SAN_LUONG,
                    SLUONG_TTIEP = info.SLUONG_TTIEP,
                    HS_NHAN = info.HS_NHAN,
                    NGAY_TAO = info.NGAY_TAO,
                    NGUOI_TAO = info.NGUOI_TAO,
                    NGAY_SUA = info.NGAY_SUA,
                    NGUOI_SUA = info.NGUOI_SUA,
                    MA_CNANG = info.MA_CNANG,
                };
                CMIS2.DB.DD_BDONG_TTHAO.InsertOnSubmit(info);
                CMIS2.DB.SubmitChanges();
                id_ls_treothao = _ID;
                CMIS2.ResetDB();
                return true;
            }
            catch (Exception ex)
            {
                maloi = ex.ToString();
                CMIS2.ResetDB();
                return false;
            }
        }
        public bool delete_DD_BDONG_TTHAO(DataTable dt, ref string maloi)
        {
            try
            {
                if (dt != null && dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        var query = from p in CMIS2.DB.DD_BDONG_TTHAO
                                    where (p.MA_DVIQLY == dt.Rows[i]["MA_DVIQLY"].ToString() && p.ID_LSU_TTHAO == Convert.ToInt64(dt.Rows[i]["ID_LSU_TTHAO"]))
                                    select p;
                        if (query != null && query.Count() > 0)
                        {
                            CMIS2.DB.DD_BDONG_TTHAO.DeleteAllOnSubmit(query.ToList());
                            CMIS2.DB.SubmitChanges();
                        }
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                maloi = ex.ToString();
                CMIS2.ResetDB(); return false;
            }
        }
        #endregion

    }
}
